﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="FineUIPro.EmptyProjectNet40.list" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   
    <title></title>
    <link rel="stylesheet"  href="res/js/jquery-ui.css" />
</head>
<body>
    <form id="form1" runat="server">
        <f:PageManager ID="PageManager1" runat="server" />
        <f:Grid ID="Grid1" IsFluid="true" CssClass="blockpanel" ShowBorder="true" ShowHeader="true" EnableCollapse="false"
            runat="server" DataKeyNames="id,Name"  AllowPaging="true" IsDatabasePaging="false" PageSize="5"
            DataIDField="id" Title="通讯录" OnRowCommand="Grid1_RowCommand" OnPreRowDataBound="Grid1_PreRowDataBound" EnableHeaderMenu="false">
            <Toolbars>
                <f:Toolbar ID="Toolbar2" Position="Bottom" runat="server" Hidden="true">
                    <Items>
                        <f:Button ID="btnNew" Text="新增" Icon="Add" EnablePostBack="false" runat="server">
                            <Listeners>
                                <f:Listener Event="click" Handler="onNewButtonClick" />
                            </Listeners>
                        </f:Button>
                        <f:Button ID="btnEdit" Text="编辑" Icon="Pencil" EnablePostBack="true" runat="server" OnClick="btnEdit_Click">
                          
                        </f:Button>
                        <f:Button ID="btnDelete" Text="删除" Icon="Delete" ConfirmText="确定删除当前数据？" OnClick="btnDelete_Click"
                            runat="server">
                        </f:Button>
                    </Items>
                </f:Toolbar>
                <f:Toolbar ID="toolbar3" Position="Top" runat="server">
                    <Items>
                         <f:ToolbarText ID="ttxttest" runat="server" Text="搜索条件：" ></f:ToolbarText>
                        <f:DropDownList ID="ddlsearchdepartment" runat="server" EmptyText="--请选择部门--" AutoSelectFirstItem="false"  >
                            <f:ListItem Text="--请选择部门--" Value="0" />
                        </f:DropDownList>
                         <f:DropDownList ID="ddlgender" runat="server" Width="120px" >
                            <f:ListItem Text="--请选择性别--" Value="-1" />
                             <f:ListItem Text="男" Value="1" />
                             <f:ListItem Text="女" Value="0" />
                        </f:DropDownList>
                       <f:TextBox ID="txtKeys"  EmptyText="请输入姓名" runat="server"></f:TextBox>
                        <f:Button ID="btnSearch" runat="server" Text="搜索" OnClick="btnSearch_Click"></f:Button>
                    </Items>
                </f:Toolbar>
            </Toolbars>
            <Columns>
                <f:TemplateField Width="60px" >
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
                    </ItemTemplate>
                </f:TemplateField>
                <f:RenderField  DataField="Name" ExpandUnusedSpace="true"
                    HeaderText="姓名">
                </f:RenderField>
             <f:TemplateField HeaderText="性别" ExpandUnusedSpace="true">
                 <ItemTemplate>
                     <%#Eval("gender").ToString()=="1"?"男":"女" %>
                 </ItemTemplate>
             </f:TemplateField>

                 <f:TemplateField HeaderText="部门" ExpandUnusedSpace="true">
                 <ItemTemplate>
                     <%#GetDepartmentName(Eval("DepartmentId").ToString()) %>
                 </ItemTemplate>
             </f:TemplateField>
           
              <f:RenderField   DataField="TelNum" ExpandUnusedSpace="true"
                    HeaderText="电话">
                </f:RenderField>
            
                <f:RenderField   DataField="Callphone" ExpandUnusedSpace="true"
                     HeaderText="手机">
                </f:RenderField>
             
           
            </Columns>
              <PageItems>
                <f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
                </f:ToolbarSeparator>
                <f:ToolbarText runat="server" Text="每页记录数：">
                </f:ToolbarText>
                <f:DropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true"
                    OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
                    <f:ListItem Text="5" Value="5" />
                    <f:ListItem Text="10" Value="10" />
                    <f:ListItem Text="15" Value="15" />
                    <f:ListItem Text="20" Value="20" />
                </f:DropDownList>
            </PageItems>
        </f:Grid>

        <f:Window ID="Window1" Title="新增记录" Hidden="true" EnableIFrame="false"
            EnableMaximize="true" Target="Self" EnableResize="true" runat="server"
            IsModal="true" Width="500px">
            <Items>
                <f:SimpleForm ID="SimpleForm1" runat="server" ShowBorder="false" ShowHeader="false" BodyPadding="10px">
                    <Items>
                        <f:HiddenField ID="hfFormID" runat="server"></f:HiddenField>
                        <f:TextBox ID="txtUserName" ShowRedStar="true" Label="姓名" Required="true" runat="server" MaxLength="50" >
                        </f:TextBox>
                        <f:RadioButtonList ID="rblFormGender" Label="性别" ShowRedStar="true" Required="true" runat="server">
                            <f:RadioItem Text="男" Value="1" />
                            <f:RadioItem Text="女" Value="0" />
                        </f:RadioButtonList>
                    
                        <f:DropDownList ID="ddlDepartment" Label="所属部门" ShowRedStar="true" Required="true" AutoSelectFirstItem="false" runat="server" EmptyText="--请选择部门--">
                            
                        </f:DropDownList>
                        <f:TextBox ID="txtTelNum" runat="server" Required="true" Label="座机号码" MaxLength="30"></f:TextBox>
                         <f:TextBox ID="txtCallPhone" runat="server" Required="true" Label="手机号码" MaxLength="20"></f:TextBox>
                     
                    </Items>
                    <Toolbars>
                        <f:Toolbar ID="Toolbar1" Position="Bottom" ToolbarAlign="Right" runat="server">
                            <Items>
                                <f:Button ID="btnSave"
                                    Icon="SystemSave" runat="server" Text="保存数据" ValidateForms="SimpleForm1" OnClick="btnSave_Click">
                                </f:Button>
                            </Items>
                        </f:Toolbar>
                    </Toolbars>
                </f:SimpleForm>
            </Items>
        </f:Window>
        <br />
        <br />
        <br />
    </form>
    <script type="text/javascript" src="res/js/jquery-ui.js"></script>
    <script type="text/javascript">
        var textbox1ID = '<%= ttxttest.ClientID %>';

        F.ready(function () {

            var cache = {};

            $('#Grid1_toolbar3_txtKeys-inputEl').autocomplete({
                minLength: 1,
                source: function (request, response) {
                    var term = request.term;
                    if (term in cache) {
                        response(cache[term]);
                        return;
                    }

                    $.getJSON("search.ashx", request, function (data, status, xhr) {
                        cache[term] = data;
                        response(data);
                    });
                }
            });

        });

    </script>
    <script>

        function renderGender(value) {
            return value == 1 ? '男' : '女';
        }


        var windowClientID = '<%= Window1.ClientID %>';
        var gridClientID = '<%= Grid1.ClientID %>';
     <%--   var btnDeleteClientID = '<%= btnDelete.ClientID %>';--%>
        var btnSaveClientID = '<%= btnSave.ClientID %>';

        var formClientID = '<%= SimpleForm1.ClientID %>';
        var hfFormIDClientID = '<%= hfFormID.ClientID %>';
        var tbxFormUserNameClientID = '<%= txtUserName.ClientID %>';
        var rblFormGenderClientID = '<%= rblFormGender.ClientID %>';

        var ddlFormMajorClientID = '<%= ddlDepartment.ClientID %>';

        var txtTelNumClientID = '<%= txtTelNum.ClientID %>';
        var txtCallPhoneClientID = '<%= txtCallPhone.ClientID %>';
        var hfFormIDClientID = '<%=hfFormID.ClientID%>';

        function onNewButtonClick(event) {
            // 重置表单字段
            F(formClientID).reset();
            F(windowClientID).setTitle('新增记录');
            F(hfFormIDClientID).setValue('');
            // 弹出窗体
            F(windowClientID).show();
           // F(windowClientID).setTitle('新增数据');
        }

        function onEditButtonClick(event) {
            showEditWindow();
        }

        function showEditWindow(rowId) {
            var grid = F(gridClientID);

            // 如果传入参数为空，则获取当前选中行
            if (!rowId) {
                var selectedRowIds = grid.getSelectedRows();
                if (!selectedRowIds.length) {
                    F.alert('请至少选择一项！');
                    return;
                }

                rowId = selectedRowIds[0];
            }

            
            F(windowClientID).setTitle('编辑数据');

            // 当前行数据
            var rowValue = grid.getRowValue(rowId);
            alert(rowValue);
            // 使用当前行数据填充表单字段
            F(hfFormIDClientID).setValue(rowId);
            F(tbxFormUserNameClientID).setValue(rowValue['Name']);
            F(rblFormGenderClientID).setValue(rowValue['Gender']);
            F(ddlFormMajorClientID).setValue(rowValue['DepartmentId']);

            F(txtTelNumClientID).setValue(rowValue['TelNum']);
            F(txtCallPhoneClientID).setValue(rowValue['Callphone']);
        

            // 弹出新增窗体
            F(windowClientID).show();
        }

    </script>
</body>
</html>